package org.bigjava.travel.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.bigjava.travel.bean.TravelRoute;
import org.bigjava.travel.dao.TravelRouteDao;
import org.bigjava.travel.service.TravelRouteService;
import org.bigjava.travel.utils.Tools;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 旅游路线业务逻辑层实现类
 */
@Service
@Component
public class TravelRouteServiceImpl implements TravelRouteService {

    @Resource
    TravelRouteDao travelRouteDao;

    @Override
    public long count() throws Exception {
        return travelRouteDao.count();
    }

    @Override
    public TravelRoute findById(Integer id) throws Exception {
        return travelRouteDao.findById(id);
    }

    @Override
    public List<TravelRoute> findList() throws Exception {
        return travelRouteDao.findList();
    }

    @Override
    public void save(TravelRoute travelRoute) throws Exception {
        travelRouteDao.save(travelRoute);
    }

    @Override
    public void update(TravelRoute travelRoute) throws Exception {
        travelRouteDao.update(travelRoute);
    }

    @Override
    public void deleteById(Integer id) throws Exception {
        travelRouteDao.deleteById(id);
    }

    @Override
    public List<TravelRoute> findByPage(int currentPage, int pageSize, String query) {
        List<TravelRoute> list = new ArrayList<TravelRoute>();
        PageHelper.startPage(currentPage, pageSize);
        if (Tools.notEmpty(query)) {
            list = travelRouteDao.findListByQuery("%" + query + "%");
        } else {
            list = travelRouteDao.findList();
        }
        PageInfo<TravelRoute> pageInfo=new PageInfo<TravelRoute>(list);
        return pageInfo.getList();
    }

    @Override
    public List<TravelRoute> findByPage(int currentPage, int pageSize) {
        List<TravelRoute> list = new ArrayList<TravelRoute>();
        PageHelper.startPage(currentPage, pageSize);
        list = travelRouteDao.indexList();
        PageInfo<TravelRoute> pageInfo=new PageInfo<TravelRoute>(list);
        return pageInfo.getList();
    }

    @Override
    public long state0count()throws Exception{
        return travelRouteDao.state0count();
    }

    @Override
    public long state1count()throws Exception{
        return travelRouteDao.state1count();
    }

    @Override
    public long state2count()throws Exception{
        return travelRouteDao.state2count();
    }
}
